package com.leetcode.Offer;

public class JZ46 {
    public int translateNum(int num) {
        //动态规划，从后往前
        String str = String.valueOf(num);
        int[] dp = new int[str.length() + 1];
        dp[0] = 1;
        dp[1] = 1;
        for (int i = 2; i <= str.length(); i++) {
            dp[i] = (dp[i - 1]) + (ifAccord(str, i - 1) * dp[i - 2]);
        }
        return dp[str.length()];
    }

    private int ifAccord(String str, int index) {//判断临近的两个数字是否能组成新的字符
        if ((str.charAt(index - 1) - '0') == 0) {//防止出现05，06这样的数
            return 0;
        } else {
            return str.charAt(index) - '0' + ((str.charAt(index - 1) - '0') * 10) > 25 ? 0 : 1;
        }
    }

    public static void main(String[] args) {
        System.out.println(new JZ46().translateNum(123123));
    }
}
